package com.eshop.api;

import org.apache.logging.log4j.LogManager;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import com.zhonghui.license.LicenseVerify;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;

public class LicenseCheckInterceptor implements HandlerInterceptor
{
    private static Logger logger;
    
    public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception {
        final LicenseVerify licenseVerify = new LicenseVerify();
        final boolean verifyResult = licenseVerify.verify();
        if (verifyResult) {
            return true;
        }
        final Map result = new HashMap();
        result.put("message", "您的证书无效，请核查服务器是否取得授权或重新申请证书！");
        result.put("status", 1000);
        response.setContentType("application/json");
        response.setStatus(400);
        response.getOutputStream().write(JSONObject.toJSONString((Object)result).getBytes());
        return false;
    }
    
    static {
        LicenseCheckInterceptor.logger = LogManager.getLogger((Class)LicenseCheckInterceptor.class);
    }
}
